﻿using Microsoft.Phone.Controls;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;

/**
 * 创建时间：2014/9/20 9:49:13
 * 作者：yong.blackcore
 * Email：itblackhole@outlook.com
 * QQ：50404503
 */
namespace YoucaiReader.Helper
{
    public class NavigateServiceHelper
    {
        private readonly static Uri DefaultStartPage;

        static NavigateServiceHelper()
        {
            NavigateServiceHelper.DefaultStartPage = new Uri(string.Concat("/",ReaderNavigatePageContants.IndexPage.ToString (),".xaml"), UriKind.Relative);
        }

        public NavigateServiceHelper()
        {
        }

        public static Uri GetNavigateUri(ReaderNavigatePageContants page, string param = "")
        {
            Uri mainPage = null;
            switch (page)
            {
                case ReaderNavigatePageContants.AboutPage:
                    mainPage = new Uri(string.Concat("/Pages/AboutPage.xaml", param), UriKind.Relative);
                    break;
                case ReaderNavigatePageContants.FeedbackPage:
                    mainPage = new Uri(string.Concat("/Pages/FeedbackPage.xaml", param), UriKind.Relative);
                    break;
                case ReaderNavigatePageContants.BookReaderPage:
                    mainPage = new Uri(string.Concat("/Pages/BookReaderPage.xaml", param), UriKind.Relative);
                    break;
                case ReaderNavigatePageContants.BookDetailPage:
                    mainPage = new Uri(string.Concat("/Pages/BookDetailPage.xaml", param), UriKind.Relative);
                    break;
                case ReaderNavigatePageContants.BookChapterPage:
                    mainPage = new Uri(string.Concat("/Pages/BookChapterPage.xaml", param), UriKind.Relative);
                    break;
                case ReaderNavigatePageContants.IndexPage:
                default:
                    mainPage = NavigateServiceHelper.DefaultStartPage;
                    break;
            }
            return mainPage;
        }

        public static bool Navigate(ReaderNavigatePageContants page, string param = "")
        {
            Uri navigateUri = NavigateServiceHelper.GetNavigateUri(page, param);
            if (!(Application.Current.RootVisual is PhoneApplicationFrame))
            {
                return false;
            }
            return ((PhoneApplicationFrame)Application.Current.RootVisual).Navigate(navigateUri);
        }
    }
}
